<?php
namespace App\Models\Factory;

use App\Models\AbsModelFactory;
use App\Models\Orm\AliBinding;
use App\Models\Orm\AliOrder;
use App\Models\Orm\AliUser;

use App\Strategies\CashStrategy;

class AliFactory extends AbsModelFactory
{

    public static function adduser($data)
    {

        $data['created_at'] =  date("Y-m-d H:i:s",time());
        $res = AliUser::updateOrCreate(['uid'=>$data['uid']],$data);
        return $res? true :false;
    }

    //往支付订单记录表里插入数据
    public static function addorder($data,$uid)
    {

        //查看生成的数组大小
        $i = count($data);
        if($i){

            foreach($data as $call){
                $call['uid'] = $uid;
                $call['created_at'] = date("Y-m-d H:i:s",time());
                $res = AliOrder::insert($call);
                if(!$res){
                    continue;
                }
            }
            $call_log =AliOrder::all()->first();
            return  empty($call_log)? false :true;
        }
    }


    public static function addbinding($data)
    {
        $data['created_at'] = date("Y-m-d H:i:s",time());
        $res = AliBinding::updateOrCreate(['uid'=>$data['uid']],$data);
        return $res? true :false;
    }

    //获取支付宝账号
    public static function getAccount($userId)
    {
        $account = AliUser::where('uid',$userId)->first();
        if($account)
        {
            return $account -> account ? CashStrategy::handleAccount($account -> account) : '';
        }
        return $account = '';
    }


}